// components/item/item.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    itemPic: {
      type: String,
      value: "../../images/defaultItemPic.png",
    },
    name: {
      type: String,
      value: "默认物品",
    },
    number: {
      type: Number,
      value: 10,
    },
    need: {
      type: Number,
      value: 0,
    },
    index: {
      type: Number,
      value: 0,
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
  },

  /**
   * 组件的方法列表
   */
  methods: {
    doDecre: function(e) {
      var needNum = this.data.need;
      if (needNum > 0) {
        needNum--;
        this.setData({
          need: needNum,
        })
        var index = this.data.index;
        this.triggerEvent("onNeedChanged", {
          index: index,
          need: this.data.need,
        })
      }
    },
    doIncre: function(e) {
      var needNum = this.data.need;
      if (needNum < this.data.number) {
        needNum++;
        this.setData({
          need: needNum,
        });
        var index = this.data.index;
        this.triggerEvent("onNeedChanged", {
          index: index,
          need: this.data.need,
        })
      }
    }
  }
})
